local poji = fk.CreateSkill {
  name = "kl__poji",
}

Fk:loadTranslationTable{
  ["kl__poji"] = "破计",
  [":kl__poji"] = "当场上进行判定时，若判定牌为锦囊牌，你可以获得此牌，并选择是否取消此判定。",

  ["#kl__poji-invoke"] = "破计： %src 的判定牌 %arg 即将生效，是否获得此牌？",
  ["#kl__poji-end"] = "破计：是否取消此判定？",

  ["$kl__poji1"] = "集古今之智，晓天下之机。",
}

poji:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target and player:hasSkill(poji.name) and data.card and data.card.type == Card.TypeTrick
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = poji.name,
      prompt = "#kl__poji-invoke:" .. target.id .. "::" .. data.card:toLogString(),
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, { skill_name = poji.name, prompt = "#kl__poji-end" }) then
      local e = room.logic:getCurrentEvent():findParent(GameEvent.SkillEffect)
      if e then
        room.logic:getCurrentEvent():addExitFunc(function()
          room:obtainCard(player, data.card, true, fk.ReasonPrey, player, poji.name)
          e:shutdown()
        end)
      end
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.kl__poji = { player, data.card }
    end
  end,
})

poji:addEffect(fk.FinishJudge, {
  mute = true,
  priority = 5,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.kl__poji and not data.extra_data.kl__poji[1].dead
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(data.extra_data.kl__poji[1], data.extra_data.kl__poji[2], true, fk.ReasonPrey, player, poji.name)
  end,
})


return poji
